
"""
    日志审计
"""

from django.db import models
from users.models import UserProfileModel

# Create your models here.


class LanDingModel(models.Model):
    """
    登陆日志
    """
    username = models.CharField(max_length=64, null=True, blank=True, verbose_name='登陆用户')
    name = models.CharField(max_length=512, null=True, blank=True, verbose_name='用户名')
    tz = models.CharField(max_length=512, null=True, blank=True, verbose_name='时区')
    type = models.CharField(max_length=512, null=True, blank=True, verbose_name='类型')
    agent = models.CharField(max_length=512, null=True, blank=True, verbose_name='代理IP')
    ip = models.CharField(max_length=128, null=True, blank=True, verbose_name='IP地址')
    city = models.CharField(max_length=128, null=True, blank=True, verbose_name='IP归属')
    why = models.CharField(max_length=128, null=True, blank=True, verbose_name='说明')
    status = models.BooleanField(default=False, verbose_name="状态")
    time = models.DateTimeField(auto_now_add=True, verbose_name='日期')

    class Meta:
        verbose_name = '登陆日志'
        verbose_name_plural = verbose_name
        ordering = ['-id']

    def __str__(self):
        return self.username


class OperationModel(models.Model):
    """
    操作日志
    """
    username = models.CharField(max_length=16, null=True, blank=True, verbose_name='用户')
    name = models.CharField(max_length=16, null=True, blank=True, verbose_name='姓名')
    mobile = models.CharField(max_length=11, default="", verbose_name="手机号")
    action = models.CharField(max_length=16, null=True, blank=True, verbose_name='动作')
    resource_type = models.CharField(max_length=128, null=True, blank=True, verbose_name='资源类型')
    resource = models.CharField(max_length=512, null=True, blank=True, verbose_name='资源')
    ip = models.CharField(max_length=128, null=True, blank=True, verbose_name='IP地址')
    time = models.DateTimeField(auto_now_add=True, verbose_name='日期')

    class Meta:
        verbose_name = '操作日志'
        verbose_name_plural = verbose_name
        ordering = ['-id']

    def __str__(self):
        return self.username


